<template>
  <div>
    <el-table :data="page.content" style="width: 100%;" :size="size">
      <el-table-column fixed="right" label="操作" width="100" v-if="buttons.length>0">
        <template slot-scope="scope">
          <el-button v-for="(button,index) in buttons" :key="index" @click="handleClick(button.type,scope.row)" type="text" size="small">
            <font-awesome-icon v-if="button.icon !== undefined" :icon="button.icon"/>
            <span v-if="button.title !== undefined">{{button.title}}</span>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column v-for="(ele,index) in template.columns" :key="index" :prop="ele.prop" :label="ele.label" :width="ele.width"></el-table-column>
    </el-table>
    <div style="margin:10px;"></div>
    <el-pagination
      style="text-align: right;"
      :size="size"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.number+1"
      :page-sizes="[10, 20, 50, 100, 200]"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.totalElements"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    page: {},
    size: { default: "mini" },
    buttons: {
      type: Array,
      default: function() {
        return [];
      }
    },
    template: {
      type: Object
    }
  },
  created() {},
  methods: {
    handleClick(type, row) {
      this.$emit("buttonClick", type, row);
    },
    handleSizeChange(data) {
      this.$emit("size-change", data);
    },
    handleCurrentChange(data) {
      this.$emit("current-change", data);
    }
  }
};
</script>